#include "stdio.h"
#include "sys/types.h"
#include "unistd.h"

int main(int argc, char const *argv[])
{
    int val=100;  
    printf("main thread %d start \n", getpid());
    pid_t pid= fork(); //copy
    if(pid < 0){
        printf("fork error \n"); //fork失败
    }else if (pid == 0)
    {
        val++;
        printf("child thread %d start,val=%d,addr=%p \n", getpid(),val,&val); //子进程 虚拟内存
    }
    else{
        val--;
        printf("main thread1 %d start, child pid=%d ,val=%d,addr=%p \n", getpid(),pid, val,&val); //父进程
    }
    
    printf("main thread %d end \n", getpid());
    return 0;
}
